package com.gemfire.onlineretailer.dao.functions;

import java.util.Set;

import com.gemstone.gemfire.cache.execute.FunctionAdapter;
import com.gemstone.gemfire.cache.execute.FunctionContext;
import com.gemstone.gemfire.cache.execute.RegionFunctionContext;
import com.gemstone.gemfire.cache.partition.PartitionRegionHelper;

public class AccountsPayableItemFunctions extends FunctionAdapter {

	@Override
	public void execute(FunctionContext fc) {
		if(fc instanceof RegionFunctionContext){
		    RegionFunctionContext context = (RegionFunctionContext)fc;
		    Set keys = context.getFilter();
		    int setSize = keys.size();
		    
		    for (Object k : keys) {
		        context.getResultSender().sendResult(
		            PartitionRegionHelper.getLocalDataForContext(context).get(k));
		      }
	    
		}
		else{
			 fc.getResultSender().lastResult(Runtime.getRuntime().freeMemory()/(1024*1024)); 
		}
	}

	@Override
	public String getId() {
		return getClass().getName();
	}


}
